class GameHardLevel {
	public lastFloorY:number = 0;
	public hasLeftWall:boolean = true;
	public hasRightWall:boolean = true;
	public isNearLeft:boolean = true;
	public floorWidth:number = 0;
	public offsetWidth:number = 0;
	public floorLeft:number = 0;
	public floorRight:number = 0;
	public floorIndex:number = 0;
	public frame:ViewRect;
	public constructor() {
	}
	public static createHardLevelByFloor(floor:GameFloor): GameHardLevel{

		return GameHardLevel.createHardLevel(floor.hardLevel.lastFloorY,floor.floorIndex);
	}
	public static createHardLevelByFloor2(floor:GameFloor): GameHardLevel{

		return GameHardLevel.createHardLevel(floor.hardLevel.lastFloorY-GameConfig.floorHeight*2,floor.floorIndex-2);
	}
	public static createFirstLevel(lastFloorY:number=0,lastFloorIndex:number=-1):GameHardLevel{
		return GameHardLevel.createHardLevel(lastFloorY,lastFloorIndex);
	}
	public static createHardLevel(lastFloorY:number=0,lastFloorIndex:number=-1,groupWidth:number=GameConfig.stageWidth):GameHardLevel{
		let hardLevel = new GameHardLevel();
		hardLevel.floorIndex = lastFloorIndex+1;
		// 每10层为一个level
		let level = Math.floor(hardLevel.floorIndex/10);
		hardLevel.isNearLeft = level%2!=0;
		hardLevel.floorWidth = groupWidth-GameConfig.floorMargin*2;
		
		// 获取每层左右开口情况
		hardLevel.getHasLeftRightWall();
		if(level>=6){
			let outWidth = level*20;
			if(outWidth>(hardLevel.floorWidth*0.25)){
				hardLevel.floorWidth = hardLevel.floorWidth-(hardLevel.floorWidth*0.25);
				hardLevel.offsetWidth = (level%5)*30;
			}else{
				hardLevel.floorWidth = hardLevel.floorWidth-outWidth;
				hardLevel.offsetWidth = 0;
			}
			
		}
		let x = 0;
		if(hardLevel.isNearLeft){
			x = GameConfig.floorMargin+hardLevel.offsetWidth;
		}else{
			x = groupWidth-hardLevel.floorWidth-GameConfig.floorMargin-hardLevel.offsetWidth;
		}
		let y = lastFloorY-GameConfig.floorHeight;
		hardLevel.lastFloorY = y;
		hardLevel.frame = new ViewRect(x,y,hardLevel.floorWidth,GameConfig.floorHeight);
		hardLevel.floorLeft = x;
		hardLevel.floorRight = x+hardLevel.floorWidth;
		return hardLevel;
	}
	private getHasLeftRightWall(){
		if(!GameConfig.isFloorTypeRateListInit){
			// 初始化数据列表
			let len = GameConfig.floorTypeRateList.length;
			for(let i=0;i<len;i++){
				let floorTypeMap = GameConfig.floorTypeRateList[i];
				let rateList = floorTypeMap.rateList;
				let len2 = rateList.length;
				let fromRate = 0.0;
				for(let j=0;j<len2;j++){
					let rateMap = rateList[j];
					rateMap["fromRate"] = fromRate;
					fromRate = fromRate + rateMap.rate;
					rateMap["toRate"] = fromRate;
				}
			}
			GameConfig.isFloorTypeRateListInit = true;
		}

		let floorIndex = this.floorIndex+1;
		let datas = [true,true];
		if(floorIndex == 1 || floorIndex%10==0){
			datas = [true,true];
		}else{
			datas = this.getRateList(floorIndex);
		}
		this.hasLeftWall = datas[0];
		this.hasRightWall = datas[1];

	}
	private getRateList(floorIndex:number):Array<any>{
		let len = GameConfig.floorTypeRateList.length;
		for(let i=0;i<len;i++){
			let floorTypeMap = GameConfig.floorTypeRateList[i];
			if(floorTypeMap.min<=floorIndex && floorTypeMap.max>=floorIndex){
				let rateList = floorTypeMap.rateList;
				let rateMap = Utils.randomFromArrayWithPersent(rateList);
				let datas = rateMap.datas;
				return datas;
			}
		}
		return [true,true];
		
	}
	
}